package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.washcar.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import ${package.Entity}.${table.entityName};
import ${package.Service}.${table.serviceName};

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
     @Resource
     private ${table.serviceName}  ${table.entityPath}Service;

     @RequestMapping("/add${table.entityName}")
     @ResponseBody
     public TableResult add${table.entityName}(${table.entityName} ${table.entityPath}){
         ${table.entityPath}.preInsert();
         boolean b = ${table.entityPath}Service.insert(${table.entityPath});
         return TableResult.Result(b);
     }

     @RequestMapping("/update${table.entityName}")
     @ResponseBody
     public TableResult update${table.entityName}(${table.entityName} ${table.entityPath}){
         ${table.entityPath}.preUpdate();
        boolean b = ${table.entityPath}Service.updateById(${table.entityPath});
         return TableResult.Result(b);
     }

     @RequestMapping("/find${table.entityName}One")
     @ResponseBody
     public TableResult find${table.entityName}One(${table.entityName} ${table.entityPath}){

        EntityWrapper<${table.entityName}> wrapper = ${table.entityPath}.getQueryWrapper();

        ${table.entityName} result = ${table.entityPath}Service.selectOne(wrapper);

		return TableResult.Result(result);
     }

     @RequestMapping("/find${table.entityName}List")
     @ResponseBody
     public TableResult find${table.entityName}List(${table.entityName} ${table.entityPath}){

        EntityWrapper<${table.entityName}> wrapper = ${table.entityPath}.getQueryWrapper();

        Page<${table.entityName}> page = ${table.entityPath}.getPageInfo();

        page = ${table.entityPath}Service.selectPage(page,wrapper);

		return TableResult.Result(page);
     }

     @RequestMapping("/delete${table.entityName}")
     @ResponseBody
     public TableResult delete${table.entityName}(${table.entityName} ${table.entityPath}){
        ${table.entityPath}.preUpdate();
        boolean b = ${table.entityPath}Service.deleteById(${table.entityPath}.getId());
        return TableResult.Result(b);
     }

}
</#if>
